//// ========================== 
//// 描述：右键生成UIPanel代码
//// 作者：MING
//// 创建时间：2021/09/01 10:16:41 
//// 版本：1.0
//// ========================== 

//using UnityEditor;
//using UnityEngine;
//using System.IO;
//using System;
//using System.Linq;

//namespace UIFrame
//{
//    public class CreateCode : MonoBehaviour
//    {
//        public static string PanelClass = @"
//using UnityEngine;
//using UnityEngine.UI;
//using MINGUI;          

//public class #ClassName# : BasePanel
//{
//    protected override void AddEvent()
//    {"
//       + "//DicItemEvent.Add(\"返回\", EventBack);" +
//@"  }
//}";

//        [MenuItem("GameObject/MINGUI/CreatePanel", priority = 0)]
//        public static void AddUIMarkMenu()
//        {
//            GameObject[] obj = Selection.gameObjects;
//            foreach (var item in obj)
//            {
//                NewClass(item);
//            }
//        }

//        public static void NewClass(GameObject go)
//        {
//            //先判断是否有这个代码
//            if (go.GetComponent<BasePanel>())
//            {
//                Debug.LogWarning("该对象以有一个继承于BasePanel的组件了，请检查后再试！");
//                return;
//            }

//            string className = go.name;
//            string path = Application.dataPath + "/Scripts/Backstage/Panels/SetPanels/" + className + ".cs";
//            string classStr = PanelClass;
//            classStr = classStr.Replace("#ClassName#", className);
//            using FileStream file = new FileStream(path, FileMode.OpenOrCreate);
//            using StreamWriter fileW = new StreamWriter(file, System.Text.Encoding.UTF8);

//            fileW.Write(classStr);
//            fileW.Flush();
//            fileW.Close();
//            file.Close();

//            Debug.Log("创建脚本:" + path + "成功!");
//            AssetDatabase.Refresh();

//            //go.AddComponent(GetType(className));
//        }

//        public static Type GetType(string name)
//        {
//            var AssemblyCSharp = AppDomain.CurrentDomain.GetAssemblies().First(v => v.FullName.StartsWith("Assembly-CSharp,"));
//            return AssemblyCSharp.GetType(name);
//        }
//    }
//}
